package com.supermap.dialogs.advance;

import javax.swing.*;
import java.awt.*;

public abstract class CJDialog extends JDialog {
    protected JButton confirmBtn;

    public CJDialog(Frame owner, String title, boolean modal, int width, int height, Object[] args) {
        super(owner, title, modal);
        initializeArgs(args);
        initialize(width, height);
    }

    private void initialize(int width, int height) {
        Rectangle parentBounds = getOwner().getBounds();
        setBounds((int) (parentBounds.getCenterX() - width / 2), (int) (parentBounds.getCenterY() - height / 2), width, height);
        setLayout(new BorderLayout());
        setResizable(false);

        confirmBtn = new JButton("确定");
        confirmBtn.addActionListener(e1 -> doConfirm());

        JPanel bottomPanel = new JPanel();
        bottomPanel.setLayout(new BorderLayout());
        bottomPanel.add(confirmBtn, BorderLayout.EAST);
        add(bottomPanel, BorderLayout.SOUTH);

        initializeCore();
    }

    public void doConfirm() {
        doConfirmCore();
    }

    protected abstract void initializeArgs(Object[] args);

    protected abstract void initializeCore();

    protected abstract void doConfirmCore();
}
